package com.itcoon.transform4j.demo.web.controller;

import com.google.common.collect.Lists;
import com.itcoon.common.core.page.PageResult;
import com.itcoon.common.web.core.response.ApiPageResponse;
import com.itcoon.common.web.core.response.ApiResponse;
import com.itcoon.transform.starter.Transformer;
import com.itcoon.transform4j.demo.domain.Student;
import com.itcoon.transform4j.demo.web.vo.StudentVIO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "02_assemble_基础篇", description = "集合,分页对象编集测试")
@RestController
@RequestMapping("/api")
public class BaseMultiAssembleController {

    @ApiOperation("获取学生列表")
    @GetMapping("/students")
    public ApiResponse<List<StudentVIO>> getStudents(){
        Student student1 = new Student();
        student1.setSid(1L);
        student1.setName("张三");

        Student student2 = new Student();
        student2.setSid(2L);
        student2.setName("李四");

        List<StudentVIO> studentVIOS = Transformer.toList(StudentVIO.class).apply(Lists.newArrayList(student1,student2)).done();
        return ApiResponse.createSuccess(studentVIOS);
    }

    @ApiOperation("获取学生分页结果")
    @GetMapping("/students2")
    public ApiPageResponse<List<StudentVIO>> getStudents2(){
        Student student1 = new Student();
        student1.setSid(1L);
        student1.setName("张三");

        Student student2 = new Student();
        student2.setSid(2L);
        student2.setName("李四");

        PageResult<Student> pageResult = new PageResult<Student>() {
            @Override
            public List<Student> getContents() {
                return Lists.newArrayList(student1, student2);
            }

            @Override
            public Integer getPageNo() {
                return 1;
            }

            @Override
            public Integer getPageSize() {
                return 10;
            }

            @Override
            public Long getTotal() {
                return 2L;
            }
        };
        PageResult<StudentVIO> studentVIOPage = Transformer.toPage(StudentVIO.class).apply(pageResult).done();
        return ApiPageResponse.createPageSuccess(studentVIOPage);
    }
}
